﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AccessProvider;

namespace Interface
{
    public partial class Main : Form
    {
        public static string loginName, password;
        DataConnection dc = new DataConnection();    
        public Main()
        {
            InitializeComponent();
        }

        private void dangNhapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            HeThong.Login login = new HeThong.Login();
            login.MdiParent = this;
            login.Show();
        }        

        private void thoatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void quanLyNDToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HeThong.QuanLyUser qlu = new HeThong.QuanLyUser();
            qlu.Activate();
            qlu.Show();
        }        

        private void tiepNhanHSMenu_Click(object sender, EventArgs e)
        {
            DSHocSinh dshs = new DSHocSinh();
            dshs.Activate();
            dshs.Show();
        }

        private void thongTinLopMenu_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            Lop.CacLopHoc clh = new Lop.CacLopHoc();
            clh.MdiParent = this;
            clh.Show();
        }

        private void dsLopMenu_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            Lop.DanhSachLop dsl = new Lop.DanhSachLop();
            dsl.MdiParent = this;
            dsl.Show();
        }

        private void monHocMenu_Click(object sender, EventArgs e)
        {
            MonHoc.DSMonHoc dsmh = new MonHoc.DSMonHoc();
            dsmh.Activate();
            dsmh.Show();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            phanQuyen(loginName);                          
        }

        public void phanQuyen(string username)
        {
            string loaiUser = dc.getLoaiUser(username);            
            switch (loaiUser)
            {
                case "GVU":                                        
                    qlhsStrip.Items[1].Visible = true;                    
                    qlhsStrip.Items[2].Visible = true;
                    qlhsStrip.Items[3].Visible = true;
                    qlhsStrip.Items[4].Visible = true;
                    qlhsStrip.Items[5].Visible = true;
                    break;
                case "GVIEN":
                    qlhsStrip.Items[4].Visible = true;
                    break;
                case "AD":
                    foreach (ToolStripMenuItem items in qlhsStrip.Items)
                    {
                        items.Visible = true;
                        foreach (ToolStripMenuItem subitems in items.DropDownItems)
                        {
                            subitems.Visible = true;
                        }
                    }
                    break;
            }                        
        }

        private void dangXuatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HeThong.Login login = new HeThong.Login();
            this.Close();
            login.Activate();
            login.Show();
        }

        private void diemMonMenu_Click(object sender, EventArgs e)
        {
            Diem.BangDiemMon bdm = new Diem.BangDiemMon();
            bdm.MdiParent = this;
            bdm.Show();
        }

        private void diemHKMenu_Click(object sender, EventArgs e)
        {
            Diem.DiemHK dhk = new Diem.DiemHK();
            dhk.MdiParent = this;
            dhk.Show();
        }                
    }
}
